package com.qf.cm.dao;

import com.qf.cm.pojo.*;
import org.apache.ibatis.annotations.*;
import org.apache.ibatis.mapping.FetchType;
import org.springframework.stereotype.Repository;

import java.util.List;

/**
 * @Description: 公用常量
 * @Data: 2022/9/7 11:23
 * @Pacakge: com.qf.cm.dao
 * @ClassName: ProjectDao
 * @Author: fan
 */
@Repository
public interface ProjectDao {
   @Select("select * from project")
    List<Project> findAllProject();
    @Select("select * from project where pid = #{pid}")
    Project findProjectByPid(@Param("pid") Integer pid);
    @Update("update project set pname = #{pname},starttime = #{starttime}, endtime = #{endtime} where pid = #{pid}")
    int updateProject(Project project);
    @Results(id = "findAll",value={
            @Result(column = "pid",property = "pid"),
            @Result(column = "pname",property = "pname"),
            @Result(column = "starttime",property = "starttime"),
            @Result(column = "endtim",property = "endtim"),
            @Result(column = "updatetime",property = "updatetime"),
            @Result(column = "did",property = "did"),
            @Result(column = "cid",property = "cid"),
            @Result(column = "status",property = "status"),
            @Result(column = "cid",property = "cid"),
            @Result(column = "did",property = "developer",javaType = Developer.class,
                  one=@One(select = "com.qf.cm.dao.DeveloperDao.findDeveloperByDid",fetchType = FetchType.EAGER)),
            @Result(column = "cid",property = "contractor",javaType = Contractor.class,
                   one = @One(select = "com.qf.cm.dao.ContractorDao.findContractorByCid",fetchType = FetchType.EAGER)),
            @Result(column = "pid",property = "stages",
                   many = @Many(select = "com.qf.cm.dao.StageDao.findStageByPid",fetchType = FetchType.EAGER)),
            @Result(column = "pid",property = "subitems",
                   many = @Many(select = "com.qf.cm.dao.SubitemDao.findSubitemByPid",fetchType = FetchType.EAGER)),
            @Result(column = "pid",property = "branches",
                   many = @Many(select = "com.qf.cm.dao.BranchDao.findBranchByPid",fetchType = FetchType.EAGER))


    })
    @Select("select * from project")
    List<Project> findAll();
    @Results(id = "findProjectAndStages",value = {
            @Result(column = "pid",property = "pid"),
            @Result(column = "pname",property = "pname"),
            @Result(column = "starttime",property = "starttime"),
            @Result(column = "endtim",property = "endtim"),
            @Result(column = "updatetime",property = "updatetime"),
            @Result(column = "did",property = "did"),
            @Result(column = "cid",property = "cid"),
            @Result(column = "status",property = "status"),
            @Result(column = "cid",property = "cid"),
            @Result(column = "pid",property = "stages",
                    many = @Many(select = "com.qf.cm.dao.StageDao.findStageByPid",fetchType = FetchType.EAGER))
    })
    @Select("select * from project")
    List<Project> findProjectAndStages();
}
